package com.heima.sjms.单例模式.饿汉式;

import com.heima.sjms.单例模式.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 陈辉
 * @data 2023 14:03
 */

public class Demo {
    private static Student stu;

    static {
        try {
            Class<Student> studentClass = Student.class;
            Constructor<Student> constructor = studentClass.getDeclaredConstructor();
            constructor.setAccessible(true);
            stu = constructor.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Student stu1 = getStu();
        Student stu2 = getStu();

        System.out.println(stu1 == stu2);
    }

    public static Student getStu(){
        return stu;
    }


}
